package fifthDay;

import java.util.Arrays;

public class CheckInclusion {
    public static boolean checkInclusion(String s1, String s2) {
        if (s1.length() > s2.length()) {
            return false;
        }
        int[] cont = new int[26];
        for (int i = 0; i < s1.length(); i++) {
            --cont[s1.charAt(i) - 'a'];
        }
        int left = 0;
        for (int i = 0; i < s2.length(); i++) {
            cont[s2.charAt(i) - 'a']++;
            while (cont[s2.charAt(i) - 'a'] > 0){
                cont[s2.charAt(left) - 'a']--;
                left++;
            }
            if (i - left + 1 == s1.length()){
                return true;
            }
        }
        return false;
    }
}
